//package cn.yly.esearch.sql4es.nlpcn;
//
//import org.elasticsearch.client.Client;
//import org.elasticsearch.index.query.QueryBuilder;
//import org.elasticsearch.index.query.QueryBuilders;
//import org.elasticsearch.index.reindex.DeleteByQueryAction;
//import org.elasticsearch.index.reindex.DeleteByQueryRequest;
//import org.elasticsearch.index.reindex.DeleteByQueryRequestBuilder;
//import org.elasticsearch.index.reindex.UpdateByQueryAction;
//import org.elasticsearch.index.reindex.UpdateByQueryRequestBuilder;
//
//public class UpdateQueryAction extends QueryAction {
//
//	public UpdateQueryAction(Client client, Update update) {
//		super(client, update);
//		this.update=update;
//	}
//
//
//	private  final Update update;
//	private UpdateByQueryRequestBuilder request;
//	
//
//	@Override
//	public SqlElasticRequestBuilder explain() throws SqlParseException {
//		this.request = new UpdateByQueryRequestBuilder(client, UpdateByQueryAction.INSTANCE);
//
//		setWhere(update.getWhere());
//
//		// maximum number of processed documents
//		if (update.getRowCount() > -1) {
//			request.size(update.getRowCount());
//		}
//
//		// set conflicts param
//		updateRequestWithConflicts();
//		SqlElasticSearchRequestBuilder
//        SqlElasticDeleteByQueryRequestBuilder deleteByQueryRequestBuilder = new SqlElasticDeleteByQueryRequestBuilder(request);
//		return deleteByQueryRequestBuilder;
//	}
//	private void setWhere(Where where) throws SqlParseException {
//		if (where != null) {
//			QueryBuilder whereQuery = QueryMaker.explan(where);
//			request.filter(whereQuery);
//		} else {
//			request.filter(QueryBuilders.matchAllQuery());
//		}
//	}
//	private void updateRequestWithConflicts() {
//		for (Hint hint : update.getHints()) {
//			if (hint.getType() == HintType.CONFLICTS && hint.getParams() != null && 0 < hint.getParams().length) {
//				String conflicts = hint.getParams()[0].toString();
//				switch (conflicts) {
//					case "proceed": request.abortOnVersionConflict(false); return;
//					case "abort": request.abortOnVersionConflict(true); return;
//					default: throw new IllegalArgumentException("conflicts may only be \"proceed\" or \"abort\" but was [" + conflicts + "]");
//				}
//			}
//		}
//	}
//
//}
